package com.linsir.lin.controller.model;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.linsir.lin.dto.CSSDTO;
import com.linsir.lin.dto.MetaFieldDTO;
import com.linsir.lin.dto.MetaObjectDTO;
import com.linsir.lin.pojo.MetaField;
import com.linsir.lin.pojo.MetaObject;
import com.linsir.lin.service.CssService;
import com.linsir.lin.service.MetaFieldService;
import com.linsir.lin.service.MetaObjectService;
import com.linsir.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @ProjectName:linsir-lin
 * @Package:com.linsir.lin.controller
 * @Title: GridController
 * @Description: TODO
 * @Create:2021/6/11 15:26 by @author:Linsir
 * @Update:2021/6/11 15:26 by @author:Linsir
 * @UpdateRemark: 初始创建
 * @Version 1.0.0
 */
@Controller
@RequestMapping("/model")
public class GridController {

    /**
     * 构建自定义的Css
     */
    @Autowired
    private CssService cssService;

    /**
     * 构建模型对象
     * */
    @Autowired
    private MetaObjectService metaObjectService;

    @Autowired
    private MetaFieldService metaFieldService;



    @RequestMapping(value = "/grid/{objectCode}",method = {RequestMethod.GET})
    public String gird(Integer objectId, ModelMap modelMap, @PathVariable("objectCode") String objectCode) throws InvocationTargetException, IllegalAccessException {
        List<CSSDTO> cssdtoList = cssService.listCSS();
        MetaObjectDTO metaObjectDTO = metaObjectService.getMetaObjectDTOByCode(objectCode);
        List<MetaFieldDTO> queryFieldDTOList = metaFieldService.listGridQueryField(objectCode);
        List<MetaFieldDTO> metaFieldDTOList = metaFieldService.listByObjectCode(objectCode);

        /*测试代码*/
        /*QueryWrapper<MetaField> queryWrapper =new QueryWrapper<MetaField>();
        queryWrapper.eq("object_code",objectCode);
        List<MetaField> metaFieldList = metaFieldService.listByQueryWrapper(queryWrapper);

        for (MetaField metaField : metaFieldList)
        {
            StringUtils.fieldCol(metaField);
        }
*/
        /*测试代码*/
        modelMap.addAttribute("metaObjectDTO",metaObjectDTO);
        modelMap.addAttribute("queryFieldDTOList",queryFieldDTOList);
        modelMap.addAttribute("cssdtoList",cssdtoList);
        modelMap.addAttribute("metaFieldDTOList",metaFieldDTOList);
        return "from/grid";
    }
}
